#Region "Imports"

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Imports MetaSapiens.PageMethods

#End Region

''' <summary>
''' Page that displays the list of customers.
''' </summary>
Partial Public Class ListCustomer
  Inherits MetaSapiens.PageMethods.BasePageWithDefaultMethod

  ''' <summary>
  ''' Displays the customers.
  ''' </summary>
  <PageMethod(True)> _
  Public Sub Display()
    Dim dataSet As CustomerData

    dataSet = New CustomerData()
    dataSet.Customer.AddCustomerRow(1, "Un")
    dataSet.Customer.AddCustomerRow(2, "Deux")

    DataList1.DataSource = dataSet.Customer

    DataBind()
  End Sub

  Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles DataList1.ItemDataBound
    Dim lnkCustomer As HyperLink
    Dim row As CustomerData.CustomerRow

    If (e.Item.ItemType <> ListItemType.AlternatingItem) And _
        (e.Item.ItemType <> ListItemType.EditItem) And _
        (e.Item.ItemType <> ListItemType.Item) And _
        (e.Item.ItemType <> ListItemType.SelectedItem) Then
      Return
    End If

    row = CType(CType(e.Item.DataItem, DataRowView).Row, CustomerData.CustomerRow)
    lnkCustomer = CType(e.Item.FindControl("lnkCustomer"), HyperLink)
    lnkCustomer.Text = row.Name
    lnkCustomer.NavigateUrl = MyPageMethods.Customers.FrmCustomer.DisplayCustomer(row.CustID)
  End Sub
End Class